<template>
  <view class="bott flex box">
	  <view v-if="dataArray.length==0" class="nodata">
		  暂无数据～
	  </view>
    <view v-for="(item, index) in dataArray" :key="index" class="item">
      <view class="gray" v-if="!isWx" >
        <img src="../../static/err.png" height="14px" width="14px"/>
        <text class="gray-text">请在微信环境访问使用</text>
      </view>
      <view class="image-container">
             <img :src="item.pic" alt="商品" :lazy-load="true" />
      </view>
      <view class="bott btt">
        <view class="text-container">
          <text>{{ item.name }}</text>
          <view class="red ellipsis">
            <img
              src="../../static/hot.png"
              alt="hot"
              width="17px"
              height="12px"
            />
            {{ item.description }}
          </view>
        </view>
        <view class="button-container">
          <wx-open-launch-weapp v-if="isWx" :username="item.ghAppid"  :path="item.actUrlMp" >
            <script type="text/wxtag-template">
              <img src="https://tp.juzicps.com/juzicps/images/20230828/1693210521661_jup.png"  alt="跳转" width="30px" height="30px"  />
            </script>
          </wx-open-launch-weapp>
          <!-- <a :href="generateMiniProgramUrl(item.actUrlMp)" target="_blank"> -->
            <img v-if="!isWx"
              src="../../static/jup.png"
              alt="跳转"
              width="22.73px"
              height="21.29px"
            />
          <!-- </a> -->
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getEleAct } from "@/api/userchannel.js";

export default {
  data() {
    return {
      appid: "wxece3a9a4c82f58c9",
      sid: "a604378d77e4400cb925bfba2d8edb35",
      dataArray: [],
      subType: 2 //subType = 2 天天领红包 subType = 3 限时会场
    };
  },
  computed: {
    isWx(){
      return this.$wechat && this.$wechat.isWechat()
    }
  },
  created() {
    const url = new URL(window.location.href);
    const params = new URLSearchParams(url.search);
    const sid = params.get("sid");
    if(sid){
      this.sid = sid;
      this.init();
    }
  },
  methods: {
    init() {
      getEleAct( this.sid,this.subType).then((res) => {
        if (res.code == 200) {
          this.dataArray = res?.data;
        }
      });
    }
  },
};
</script>

<style>
.flex {
  flex-wrap: wrap;
}

.bott {
  justify-content: space-between;
  display: flex;
}
.box{
  width: 96vw;
    margin: 0 2vw;
}
.btt {
  width: 44vw;
}

.item {
  height: 150px;
  margin-bottom: 10px;
  width: 45vw;
  padding: 0 3px;
  background-color: #fff;
    border-radius: 10px;
    position: relative;
}

.image-container {
  height: 94px;
}

.image-container img {
  height: 100%;
  border-radius: 10px;
  width: auto;
}

.ellipsis {
  white-space: nowrap;
  /* 禁止换行 */
  overflow: hidden;
  /* 超出部分隐藏 */
  text-overflow: ellipsis;
  /* 显示省略号 */
}

.text-container {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 0;
}

.red {
  max-width: 34vw;
  color: #fb5339;
  margin: 5px 0;
  font-size: 10px;
}

.button-container {
  display: flex;
  justify-content: center;
  align-items: center;
}
.gray{
  height: 19px;
  border-radius: 30px;
  background: rgba(204, 204, 204, 1);
  padding: 1px 8px;
  position: absolute;
    top: 30%;
    /* left: 50%; */
    transform: translate(6%, -30%);
}
.gray img{
  vertical-align: center;
}
.gray-text{
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0px;
  line-height: 20px;
  color: rgba(128, 128, 128, 1);
  text-align: left;
  vertical-align: top;
}
.nodata{
	width: 100%;
	color:gray;
	text-align: center;
	line-height: 100px;
}
</style>
